﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class UIAP05 : ViewBase
    {
        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (!IsManage)
            {
                VICC_WFEVENTS.SVWF.KS02(this.RUNID);
            }

            base.ManageCommand(sender, e);
        }
        public void ResetSeq(object sender, RoutedEventArgs e)
        {
            if (!TMV.IsITX)
            {
                return;
            } 
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                KEY = "";
                APAKMASCHZE = "";
                APAKME = "";
            }
            else
            {
                KEY = TMV.APAKANRKRS + TMV.APAKALFDNR + TMV.APAKAFOLGE + TMV.APAKAEVOR + TMV.APAKPKSTKRS + TMV.APAKPKST + TMV.APAKMTYP + TMV.APAKAGANG + TMV.APAKEVARHNR + TMV.APAKEVARUNR;
                APAKMASCHZE = TMV.APAKMASCHZE;
                APAKME = TMV.APAKME;
            }
        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            foreach(DataRow row in TBMain.Rows)
            {
                TMV.UpdateAPARTK(row,0);
            } 
            base.OnSave();
        }
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.DAPL01(dwMaster);
            PM["ANRKRS"] = dwMaster["APAKANRKRS"].ToString();
            PM["ALFDNR"] = dwMaster["APAKALFDNR"].ToString();
            PM["AFOLGE"] = dwMaster["APAKAFOLGE"].ToString();
            PM["AEVOR"] = dwMaster["APAKAEVOR"].ToString();
            TMV.APE.DLAPE(PM);
            filter = "APAKANRKRS='" + dwMaster["APAKANRKRS"].ToString() + "' AND APAKALFDNR='" + dwMaster["APAKALFDNR"].ToString()
                + "' AND APAKAFOLGE='" + dwMaster["APAKAFOLGE"].ToString()
                + "' AND APAKAEVOR='" + dwMaster["APAKAEVOR"].ToString()
                + "'";
            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {

                row.Delete();
            }
            TBMain.AcceptChanges();
            //base.DeleteCommand(sender, e);
        }


    }
    public partial class UIAP05
    {
        public VAPARTK TMV
        {
            get
            {
                return (VAPARTK)MV;
            }
        }
        #region ==KST===========
        public static readonly DependencyProperty KSTProperty = DependencyProperty.Register("KST",
            typeof(string), typeof(UIAP05),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKSTChanged));
        public string KST
        {
            get
            {
                return (string)GetValue(KSTProperty);
            }
            set
            {
                SetValue(KSTProperty, value);
                OnKSTChg(value);
            }
        }
        private static void OnKSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAP05;
            if (src != null)
            {
                src.KST = (string)e.NewValue;
            }
        }
        public virtual void OnKSTChg(string value)
        { }
        #endregion

        #region ==AGANG===========
        public static readonly DependencyProperty AGANGProperty = DependencyProperty.Register("AGANG",
            typeof(string), typeof(UIAP05),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAGANGChanged));
        public string AGANG
        {
            get
            {
                return (string)GetValue(AGANGProperty);
            }
            set
            {
                SetValue(AGANGProperty, value);
                OnAGANGChg(value);
            }
        }
        private static void OnAGANGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAP05;
            if (src != null)
            {
                src.AGANG = (string)e.NewValue;
            }
        }
        public virtual void OnAGANGChg(string value)
        { }
        #endregion

        #region ==AMTYP===========
        public static readonly DependencyProperty AMTYPProperty = DependencyProperty.Register("AMTYP",
            typeof(string), typeof(UIAP05),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAMTYPChanged));
        public string AMTYP
        {
            get
            {
                return (string)GetValue(AMTYPProperty);
            }
            set
            {
                SetValue(AMTYPProperty, value);
                OnAMTYPChg(value);
            }
        }
        private static void OnAMTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAP05;
            if (src != null)
            {
                src.AMTYP = (string)e.NewValue;
            }
        }
        public virtual void OnAMTYPChg(string value)
        { }
        #endregion

        #region ==LIEFNR===========
        public static readonly DependencyProperty LIEFNRProperty = DependencyProperty.Register("LIEFNR",
            typeof(string), typeof(UIAP05),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLIEFNRChanged));
        public string LIEFNR
        {
            get
            {
                return (string)GetValue(LIEFNRProperty);
            }
            set
            {
                SetValue(LIEFNRProperty, value);
                OnLIEFNRChg(value);
            }
        }
        private static void OnLIEFNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAP05;
            if (src != null)
            {
                src.LIEFNR = (string)e.NewValue;
            }
        }
        public virtual void OnLIEFNRChg(string value)
        { }
        #endregion

        #region ==APAKME===========
        public static readonly DependencyProperty APAKMEProperty = DependencyProperty.Register("APAKME",
            typeof(string), typeof(UIAP05),
            new FrameworkPropertyMetadata("1", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAPAKMEChanged));
        public string APAKME
        {
            get
            {
                return (string)GetValue(APAKMEProperty);
            }
            set
            {
                SetValue(APAKMEProperty, value);
                OnAPAKMEChg(value);
            }
        }
        private static void OnAPAKMEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAP05;
            if (src != null)
            {
                src.APAKME = (string)e.NewValue;
            }
        }
        public virtual void OnAPAKMEChg(string value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.APAKME = APAKME;
        }
        #endregion
        #region ==APAKMASCHZE===========
        public static readonly DependencyProperty APAKMASCHZEProperty = DependencyProperty.Register("APAKMASCHZE",
            typeof(string), typeof(UIAP05),
            new FrameworkPropertyMetadata("MI", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAPAKMASCHZEChanged));
        public string APAKMASCHZE
        {
            get
            {
                return (string)GetValue(APAKMASCHZEProperty);
            }
            set
            {
                SetValue(APAKMASCHZEProperty, value);
                OnAPAKMASCHZEChg(value);
            }
        }
        private static void OnAPAKMASCHZEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAP05;
            if (src != null)
            {
                src.APAKMASCHZE = (string)e.NewValue;
            }
        }
        public virtual void OnAPAKMASCHZEChg(string value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.APAKMASCHZE = APAKMASCHZE;
        }
        #endregion

        #region ==VU1===========
        public static readonly DependencyProperty VU1Property = DependencyProperty.Register("VU1",
            typeof(string), typeof(UIAP05),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVU1Changed));
        public string VU1
        {
            get
            {
                return (string)GetValue(VU1Property);
            }
            set
            {
                SetValue(VU1Property, value);
                OnVU1Chg(value);
            }
        }
        private static void OnVU1Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAP05;
            if (src != null)
            {
                src.VU1 = (string)e.NewValue;
            }
        }
        public virtual void OnVU1Chg(string value)
        { }
        #endregion


    }
}
